package com.uzai.console.web.xxljob;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.service.alipaydetail.AlipayTradeSyncService;
import com.uzai.console.service.fd.FdFollowSendSyncService;
import com.uzai.console.service.hdk.HdkGoodsService;
import com.uzai.console.service.lly.LlyGoodsService;
import com.uzai.console.service.mini.MiniTradeSyncService;
import com.uzai.console.service.pyq.PyqAutoSendService;
import com.uzai.console.service.pyq.PyqFollowSendSyncService;
import com.uzai.console.service.pyq.PyqJobSyncService;
import com.uzai.console.service.tb.tbpunishorder.TbPunishOrderSyncService;
import com.uzai.console.service.xxljob.XxlJobSyncService;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * XxlJob调用
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "XxlJob调用方法",tags = "系统设置|XxlJob调用方法")
@ApiSort(17)
@RestController
public class XxlJobController extends BaseController {

    @Autowired
    private XxlJobSyncService xxlJobSyncService;
    @Autowired
    private AlipayTradeSyncService alipayTradeSyncService;
    @Autowired
    private HdkGoodsService hdkGoodsService;
    @Autowired
    private PyqAutoSendService pyqAutoSendService;
    @Autowired
    private PyqFollowSendSyncService pyqFollowSendSyncService;
    @Autowired
    private LlyGoodsService llyGoodsService;
    @Autowired
    private TbPunishOrderSyncService tbPunishOrderSyncService;
    @Autowired
    private PyqJobSyncService pyqJobSyncService;
    @Autowired
    private MiniTradeSyncService miniTradeSyncService;
    @Autowired
    private FdFollowSendSyncService fdFollowSendSyncService;

    @ApiOperation(value = "机器人掉线检测报警消息（2分钟执行一次）", notes = "机器人掉线检测报警消息（2分钟执行一次）")
    @ApiOperationSupport(order = 1)
    @PostMapping("/xxlJob/deviceOffLineAlarmMsg")
    public Object deviceOffLineAlarmMsg(){
        //个人微信机器人
        xxlJobSyncService.deviceWechatOffLineAlarmMsg();
        //企业微信机器人(目前企业微信还未实现报警规则功能)
        xxlJobSyncService.deviceWxworkInfoOffLineAlarmMsg();
        return true;
    }

    @ApiOperation(value = "机器人授权到期（2分钟执行一次）", notes = "机器人授权到期（2分钟执行一次）")
    @ApiOperationSupport(order = 2)
    @PostMapping("/xxlJob/deviceExpiredAlarmMsg")
    public Object deviceExpiredAlarmMsg(){
        //个人微信机器人
        xxlJobSyncService.deviceWechatExpiredAlarmMsg();
        //企业微信机器人(目前企业微信还未实现报警规则功能)
        xxlJobSyncService.deviceWxworkExpiredAlarmMsg();
        //淘宝联盟到期报警
        xxlJobSyncService.tbTokenExpiredAlarmMsg();
        //抖客联盟到期报警(2023-08-08需求修改，暂时屏蔽抖音联盟到期报警功能)
        //xxlJobSyncService.dyTokenExpiredAlarmMsg();
        //拼多多联盟到期报警
        xxlJobSyncService.pddTokenExpiredAlarmMsg();
        //唯品会联盟到期报警
        xxlJobSyncService.vphTokenExpiredAlarmMsg();
        return true;
    }

    @ApiOperation(value = "在线查询支付宝支付结果（30秒执行一次）", notes = "在线查询支付宝支付结果（30秒执行一次）")
    @ApiOperationSupport(order = 3)
    @PostMapping("/alipayDetail/alipayTradeQuery")
    public Object alipayTradeQuery(){
        //查询支付宝支付
        alipayTradeSyncService.alipayTradeQuery();
        //查询提现个人支付宝批量转账
        alipayTradeSyncService.alipayMchBatchQuery();
        //小程序交易记录
        miniTradeSyncService.miniTradeQuery();
        return true;
    }

    @ApiOperation(value = "更新好单库最新商品（5分钟执行一次）", notes = "更新好单库最新商品（5分钟执行一次）")
    @ApiOperationSupport(order = 4)
    @PostMapping("/xxlJob/downLoadHdkGoodsSync")
    public Object downLoadHdkGoodsSync(){
        //下载好单库商品
        hdkGoodsService.downLoadHdkGoodsSync();
        //删除好单库30天之前的商品
        hdkGoodsService.deleteHdkGoodsSync();
        //下载老林云链接商品
        llyGoodsService.downLoadLlyGoodsSync();
        //删除老林云30天之前的商品
        llyGoodsService.deleteLlyGoodsSync();
        //合并处理机器人PC端和移动端授权
        //xxlJobSyncService.handerDeviceAuthForPcAndMobile();
        //淘宝处罚订单自动扣款线程
        tbPunishOrderSyncService.autoChargebackHanderSync();
        //自动刷新抖客联盟
        //xxlJobSyncService.autoRefreshDyTokenAuth();
        //自动检测免单商品是否下架
        xxlJobSyncService.autoCheckMdGoodsDrop();
        //自动检测免单商品兑换记录是否过期
        xxlJobSyncService.autoCheckMdExchangeExpired();
        //快站域名到期报警
        xxlJobSyncService.kuaizhanDomainExpiredAlarmMsg();
        //刷新第三方平台托管微信小程序授权刷新
        xxlJobSyncService.refreshMiniComponentAuthSync();
        //同步处理自动建群任务
        xxlJobSyncService.reloadGroupCreateTask();
        return true;
    }

    @ApiOperation(value = "自动发送朋友圈（1分钟执行一次）", notes = "自动发送朋友圈（1分钟执行一次）")
    @ApiOperationSupport(order = 5)
    @PostMapping("/xxlJob/autoSendPyq")
    public Object autoSendPyq(){
        //自动处理发送朋友圈
        xxlJobSyncService.autoSendPyqSync();
        //自动处理自动跟发-发送朋友评论
        xxlJobSyncService.autoSendPyqCommentSync();
        //删除过期的发送朋友跟发功能
        pyqFollowSendSyncService.deletePyqFollowSendSync();
        //自动发送发单
        xxlJobSyncService.autoSendFdSync();
        //检查小程序团购订单30分钟是否未支付
        xxlJobSyncService.autoCheckMiniOrderSync();

        //自动添加被动僵尸粉任务
        xxlJobSyncService.autoZombieFanPassiveTask();

        //自动清楚被动僵尸粉发送记录（只保留24小时）
        xxlJobSyncService.autoDeleteZombieFanPassiveTaskSendInfo();

        //删除发单跟发历史数据
        fdFollowSendSyncService.deleteFdFollowedMsgSync();

        return true;
    }

    @ApiOperation(value = "自动下载淘宝处罚订单(凌晨3点半)", notes = "自动下载淘宝处罚订单(凌晨3点半)")
    @ApiOperationSupport(order = 6)
    @PostMapping("/xxlJob/autoDownloadTbPunishOrder")
    public Object autoDownloadTbPunishOrder(){
        //自动下载淘宝处罚订单
        xxlJobSyncService.autoDownloadTbPunishOrder();

        //自动清理淘宝处罚订单历史数据(90天前的未处理的处罚订单数据)
        tbPunishOrderSyncService.deleteTbPunishOrderHistorySync();


        //删除无效的发单商品参数变量-没有在使用的发单变量参数
        xxlJobSyncService.handerFdGoodsPara();

        //删除7天前的发单官方采集群采集消息
        tbPunishOrderSyncService.deleteFdFollowGroupMsgHistorySync();

        //自动刷新个人微信通讯录
//        xxlJobSyncService.refreshWxcontacts();

        //自动刷新企业微信通讯录
//        xxlJobSyncService.refreshWxworkContacts();

        //删除朋友圈列表历史记录(10天之前)
        xxlJobSyncService.deletePyqJobHistorySync();

        //删除社群群发列表历史记录(10天之前）
        xxlJobSyncService.deleteFdSendJobHistorySync();

        //封装SOP任务
        xxlJobSyncService.autoSopTask();

        //自动清理钉钉报警群免费消息数
        xxlJobSyncService.autoRefreshDingWarningGroup();

        return true;
    }

    @ApiOperation(value = "自动清理僵尸粉任务(5秒调用一次)", notes = "自动清理僵尸粉任务(5秒调用一次)")
    @ApiOperationSupport(order = 7)
    @PostMapping("/xxlJob/autoCheckZomBieFanTask")
    public Object autoCheckZomBieFanTask(){
        //自动检测僵尸粉任务
        xxlJobSyncService.autoCheckZomBieFanTask();

        //自动清除僵尸粉任务
        xxlJobSyncService.autoDeleteZomBieFanTask();

        //自动下载订单
        xxlJobSyncService.autoOrderPull();

        //群内自动添加好友任务
        xxlJobSyncService.autoWxqAddFriendTask();

        //清理SOP任务明细
        xxlJobSyncService.autoSopTaskAddInfo();

        //自动刷新微信群通讯录任务
        xxlJobSyncService.autoWxqContactRefresh();

        //处理发单跟发消息
        fdFollowSendSyncService.sendFollowSendMsg();

        return true;
    }

    @ApiOperation(value = "机器人话费查询（每天早上9点执行一次）", notes = "机器人话费查询（每天早上9点执行一次）")
    @ApiOperationSupport(order = 8)
    @PostMapping("/xxlJob/autoSendDevicePhoneBalTask")
    public Object autoSendDevicePhoneBalTask(){
        //个人微信机器人移动端自动发送话费查询
        xxlJobSyncService.autoSendDeviceWechatPhoneBalTask();
        return true;
    }

    @ApiOperation(value = "自动清理订单（每天凌晨2点执行一次，因为需要修改运营商的订单统计数据，只能放到2点，因为统计那边任务是3点处理）", notes = "自动清理订单（每天凌晨2点执行一次，只能放到2点，因为统计那边任务是3点处理）")
    @ApiOperationSupport(order = 9)
    @PostMapping("/xxlJob/autohanderExpiredOrdersTask")
    public Object autohanderExpiredOrdersTask(){
        //自动清理过期订单
        xxlJobSyncService.handerExpiredOrders();
        return true;
    }

    @ApiOperation(value = "合同签署协议查询（2分钟查询一次）", notes = "合同签署协议查询（2分钟查询一次）")
    @ApiOperationSupport(order = 8)
    @PostMapping("/xxlJob/contractSignPollingTask")
    public Object contractSignPollingTask(){
        //合同签署协议查询
        xxlJobSyncService.contractSignPollingTask();
        return true;
    }


}
